//
//  WmcRemarkCell.swift
//  YPWatermarkCamera
//
//  Created by 赵新 on 2022/4/11.
//

import UIKit
import YPBedrock

class WmcRemarkCell: WmcBaseTableCell {
    lazy var backgroundColorView: UIView = {
        let view = UIView()
        view.layer.cornerRadius = 4
        view.layer.masksToBounds = true
        view.backgroundColor = .wmc_grayH19_F5F5F5
        return view
    }()

    /// 删除按钮
    lazy var deleteBtn: UIButton = {
        let btn = UIButton()
        btn.setImage("close".wmc_image.yp.set(tintColor: UIColor.wmc_grayH8_8A8A99), for: .normal)
        return btn
    }()

    /// 索引
    var indexPath: IndexPath?

    /// 模型
    var model: WmcRemarkHistoryModel?
    
    /// 删除记录
    var deleteRemarkBlock: YPBlock.TwoParam<IndexPath, WmcRemarkHistoryModel>?

    override func makeUI() {
        addSubview(backgroundColorView)
        backgroundColorView.snp.makeConstraints { make in
            make.top.equalTo(Wmc_standardEdge.top)
            make.left.equalTo(Wmc_standardEdge.left)
            make.right.equalTo(-Wmc_standardEdge.right)
            make.bottom.equalToSuperview()
        }

        backgroundColorView.addSubview(deleteBtn)
        deleteBtn.snp.makeConstraints { make in
            make.right.equalTo(-8)
            make.top.bottom.equalToSuperview()
            make.width.equalTo(23)
        }

        backgroundColorView.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { make in
            make.top.bottom.equalToSuperview()
            make.left.equalTo(Wmc_standardEdge.left)
            make.right.equalTo(deleteBtn.snp.left)
        }
        
        deleteBtn.yp.addEvent { [weak self] _ in
            guard let weakSelf = self,
                  let indexPath = weakSelf.indexPath,
                  let model = weakSelf.model else { return }
            weakSelf.deleteRemarkBlock?(indexPath, model)
        }
    }

    func configModel(_ model: WmcRemarkHistoryModel) {
        self.model = model
        titleLabel.text = model.perviewHistoryRemark
    }
}
